home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 036a / pmfinder.zip / LZH.C < prev    next >
Text File  |  1991-12-05  |  3KB  |  92 lines

  1. #include <os2.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <io.h>         /* needed for open, close, read, write, */
  6.                         /* filelength, and eof */
  7. #include <fcntl.h>      /* needed for open mode arguments */
  8. #include <sys\types.h>  /* needed for file types */
  9. #include <sys\stat.h>   /* needed for status flags */
  10. #include <malloc.h>     /* needed for _memmax, malloc. and free */
  11.  
  12. #include "archive.h"
  13. #include "lzh.h"
  14.  
  15. extern BOOL pascal fContinue;
  16.  
  17. /*
  18.     This module performs the LZH file search.
  19.     These functions have changed slightly from
  20.     Don A. Williams orginal code.
  21.     I've removed references to global variables.
  22.  *
  23.  */
  24. /***********************************************************************
  25.  * DoLzh is the main routine to process an entire LZH file             *
  26.  ***********************************************************************/
  27.  
  28.  void
  29. DoLzh (char *Pattern,char *Path,HWND hwndListBox)
  30. {
  31.    FILE *LzhFile;
  32.    LZH_HEADER LzhHead;
  33.    char szListBox[260];
  34.    char *p;
  35.    char V_Name[14], V_Path[65];
  36.    char *Name;
  37.  
  38.    if ( (LzhFile = fopen(Path, "rb")) == NULL )
  39.    {
  40.       strcpy(szListBox,
  41.              "LzhFile Error - Unable to open - ");
  42.       strcat(szListBox,Path);
  43.       AddToListBox(hwndListBox,szListBox);
  44.    }
  45.    else
  46.    {
  47.       while ( (Name = GetEntry(LzhFile, &LzhHead)) != NULL && fContinue )
  48.       {
  49.          if ( (p = strrchr(Name, '\\')) != NULL) ++p;
  50.          else p = Name;
  51.          if ( Match(p,Pattern) )
  52.          {
  53.             strcpy(V_Name, p);
  54.             strcpy(V_Path, Path);
  55.             sprintf(szListBox,"%s--> (%s)", V_Path, V_Name);
  56.             AddToListBox(hwndListBox,szListBox);
  57.          }
  58.       free(Name);
  59.       }
  60.  
  61.       fclose(LzhFile);
  62.    }
  63. }
  64. /***********************************************************************
  65.  * GetEntry reads and verifys the next entry in the distributed        *
  66.  * directory of an LZH file.                                           *
  67.  ***********************************************************************/
  68.  
  69.  char *
  70. GetEntry (FILE *LzhFile, LZH_HEADER *LzhDir) {
  71.    size_t Len;
  72.    char *Name;
  73.  
  74.    if ( (Len = fread(LzhDir, 1, sizeof(LZH_HEADER), LzhFile)) < 2) {
  75.       if ( (Len != 1) || (LzhDir->HeadSize != 0X00) ) {
  76.          /*Couldn't read header*/
  77.          return(NULL);
  78.          }
  79.       return(NULL);
  80.       }
  81.  
  82.    if ( (Name = malloc(LzhDir->FileNameLength + 1)) == NULL) {
  83.       /*Insufficient memory for file name */
  84.       return(NULL);
  85.       }
  86.    fread(Name, 1, LzhDir->FileNameLength, LzhFile);
  87.    Name[LzhDir->FileNameLength] = '\0';
  88.  
  89.    fseek(LzhFile, sizeof(unsigned) + LzhDir->CompressedSize, SEEK_CUR);
  90.    return(Name);
  91.    }
  92.